﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Net;

namespace Npu_Platform
{
    public partial class LoginForm : Form
    {
        Client client;
        public LoginForm()
        {
            InitializeComponent();
        }

        private void button_Login_Click(object sender, EventArgs e)
        {
            client.UserName = textBox_UserName.Text;
            client.Password = textBox_Pwd.Text;
            this.Hide();
            ConnectForm connForm = new ConnectForm(client);
            connForm.ShowDialog();
            this.Show();
        }

        private void LoginForm_Load(object sender, EventArgs e)
        {
            try
            {
                StreamReader objReader = new StreamReader(".\\ServerConfig.svc");
                string sLine = "";
                ArrayList arrText = new ArrayList();
                while (sLine != null)
                {
                    sLine = objReader.ReadLine();
                    if (sLine != null)
                        arrText.Add(sLine);
                }
                objReader.Close();
                client = new Client(IPAddress.Parse(arrText[1].ToString()), int.Parse(arrText[3].ToString()));
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button_Exit_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void LoginForm_Activated(object sender, EventArgs e)
        {
            if (textBox_UserName.Text == "")
                textBox_UserName.Focus();
            
        }

    }
}
